package com.huishu.gateway.properties;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;

import java.util.ArrayList;
import java.util.List;

/**
 * 忽略token 配置类
 */
@RefreshScope
@Component
@Data
@ConfigurationProperties(prefix = "ignore.token")
public class IgnoreTokenProperties {
    private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();

    private List<String> uri = new ArrayList<>();

    public boolean isIgnoreToken(String path) {
        return getUri().stream().anyMatch((uri) -> path.startsWith(uri) || ANT_PATH_MATCHER.match(uri, path));
    }

    public static void main(String[] args) {
        IgnoreTokenProperties ignoreTokenProperties = new IgnoreTokenProperties();
        System.out.println(JSON.toJSON(ignoreTokenProperties.uri));
    }
}
